package com.chuji.crmcj.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.bean.BeforClientInfo;
import com.chuji.crmcj.utils.UIUtils;

/**
 * Created by w.pitt on 2016/1/18.
 */
public class ExpandLvAdapter extends BaseExpandableListAdapter {
    private Context mContext;
    private BeforClientInfo beforClientInfo;
    private ExpandableListView mElvBeforeData;
    private ImageView mArrow;


    private LinearLayout rl_client_info;
    private TextView tv_updata_time;
    private TextView tv_car_purpose;
    private TextView carBudget;
    private TextView tv_buy_type;
    private TextView carUser;
    private TextView carSeries;
    private TextView carModel;
    private TextView carConfiguration;
    private TextView carColor;
    private TextView competingModels;
    private TextView reason;


    public ExpandLvAdapter(Context mContext, BeforClientInfo beforClientInfo, ExpandableListView mElvBeforeData) {
        this.mContext = mContext;
        this.beforClientInfo = beforClientInfo;
        this.mElvBeforeData = mElvBeforeData;
    }

    @Override
    public int getGroupCount() {
        return beforClientInfo.getApiParamObj().size();
    }

    @Override
    public int getChildrenCount(int i) {
        return i;
    }

    @Override
    public Object getGroup(int position) {
        return beforClientInfo.getApiParamObj().get(position);
    }

    @Override
    public Object getChild(int i, int i1) {
//        return beforClientInfo.getApiParamObj().get(i);
        return 1;
    }

    @Override
    public long getGroupId(int position) {
        return position;
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
        int totalGroup = getGroupCount();
        for (int i = 0; i < totalGroup; i++) {
            if (i != groupPosition) {
                mElvBeforeData.collapseGroup(i);
                mArrow.setImageDrawable(UIUtils.getDrawable(R.drawable.icondown));
                this.notifyDataSetChanged();
            }
        }
    }

    @Override
    public long getChildId(int i, int i1) {
        return i;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean isExpanded, View view, ViewGroup viewGroup) {
        view = view.inflate(mContext, R.layout.layout_olddata_group, null);
        mArrow = (ImageView) view.findViewById(R.id.iv_arrow);
        if (!isExpanded) {
            mArrow.setImageDrawable(UIUtils.getDrawable(R.drawable.icondown));
        } else {
            mArrow.setImageDrawable(UIUtils.getDrawable(R.drawable.iconup));
        }
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        view = View.inflate(mContext, R.layout.layout_olddata_child, null);
        TextView mTvOldData = (TextView) view.findViewById(R.id.tv_old_data);
        TextView mTvUpTime = (TextView) view.findViewById(R.id.tv_updata_time);


        tv_updata_time = (TextView) view.findViewById(R.id.tv_updata_time);
        tv_car_purpose = (TextView) view.findViewById(R.id.tv_car_purpose);
        carBudget = (TextView) view.findViewById(R.id.CarBudget);
        tv_buy_type = (TextView) view.findViewById(R.id.tv_buy_type);
        carUser = (TextView) view.findViewById(R.id.CarUser);
        carSeries = (TextView) view.findViewById(R.id.CarSeries);
        carModel = (TextView) view.findViewById(R.id.CarModel);
        carConfiguration = (TextView) view.findViewById(R.id.CarConfiguration);
        carColor = (TextView) view.findViewById(R.id.CarColor);
        competingModels = (TextView) view.findViewById(R.id.CompetingModels);
        reason = (TextView) view.findViewById(R.id.Reason);

//
//        tv_updata_time.setText(beforClientInfo.getApiParamObj().get().getUpdateTime());
//        tv_car_purpose.setText(clientDetailInfo.getApiParamObj().get(0).getCarPurpose());
//        carBudget.setText(clientDetailInfo.getApiParamObj().get(0).getCarBudget() + "");
//        tv_buy_type.setText(clientDetailInfo.getApiParamObj().get(0).getCarMode());
//        carUser.setText(clientDetailInfo.getApiParamObj().get(0).getCarUser());
//        carSeries.setText(clientDetailInfo.getApiParamObj().get(0).getCarSeries());
//        carModel.setText(clientDetailInfo.getApiParamObj().get(0).getCarModel());
//        carConfiguration.setText(clientDetailInfo.getApiParamObj().get(0).getCarConfiguration());
//        carColor.setText(clientDetailInfo.getApiParamObj().get(0).getCarColor());
//        competingModels.setText(clientDetailInfo.getApiParamObj().get(0).getCompetingModels());
//        reason.setText(clientDetailInfo.getApiParamObj().get(0).getReason());


        mTvUpTime.setVisibility(View.INVISIBLE);
        mTvOldData.setVisibility(View.INVISIBLE);
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
}
